From 9879a0a5f621a4ae44b2d9dc62a0175404c05f8f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 6 Nov 2014 08:58:01 -0800 Subject: [PATCH] Pass `-C prefer-dynamic` for dylib dependencies --- src/cargo/ops/cargo_rustc/mod.rs | 5 ++++- tests/test_cargo_compile.rs | 2 +- tests/test_cargo_profiles.rs | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index 9b2c3bf78..ad7ef6890 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -491,7 +491,10 @@ fn build_base_args(cx: &Context, .rpath(root_profile.get_rpath()) } - if profile.is_for_host() { + let prefer_dynamic = profile.is_for_host() || + (crate_types.contains(&"dylib") && + pkg.get_package_id() != cx.resolve.root()); + if prefer_dynamic { cmd = cmd.arg("-C").arg("prefer-dynamic"); } diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index 7b4094514..d8b034f4d 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -819,7 +819,7 @@ test!(verbose_release_build_deps { execs().with_status(0).with_stdout(format!("\ {compiling} foo v0.0.0 ({url}) {running} `rustc {dir}{sep}foo{sep}src{sep}lib.rs --crate-name foo \ - --crate-type dylib --crate-type rlib \ + --crate-type dylib --crate-type rlib -C prefer-dynamic \ --opt-level 3 \ --cfg ndebug \ -C metadata=[..] \ diff --git a/tests/test_cargo_profiles.rs b/tests/test_cargo_profiles.rs index f7e5024cb..8813a4994 100644 --- a/tests/test_cargo_profiles.rs +++ b/tests/test_cargo_profiles.rs @@ -82,7 +82,7 @@ test!(top_level_overrides_deps { execs().with_status(0).with_stdout(format!("\ {compiling} foo v0.0.0 ({url}) {running} `rustc {dir}{sep}foo{sep}src{sep}lib.rs --crate-name foo \ - --crate-type dylib --crate-type rlib \ + --crate-type dylib --crate-type rlib -C prefer-dynamic \ --opt-level 1 \ -g \ -C metadata=[..] \ -- 2.30.2